package com.seccen;

import javax.swing.*;
import java.awt.*;
import java.util.Random;

public class MyDay extends JPanel implements Runnable {
    private int[] xx=new int[300];
    private int[] yy=new int[300];
    public MyDay(){
        for (int i = 0; i <xx.length ; i++) {
            xx[i]=new Random().nextInt(1024);
            yy[i]=new Random().nextInt(800);

        }
    }
    @Override
    public void paint(Graphics g) {
        super.paint(g);
        this.setBackground(Color.black);
        for (int i=0;i<xx.length;i++){
            g.setColor(new Color(new Random().nextInt(0xffffff)));
            g.setFont(new Font("宋体",Font.BOLD,
                    new Random().nextInt(10)+20 ));
            g.drawString("*", xx[i],yy[i]);


        }
    }

    @Override
    public void run() {
           while (true){
               for (int i = 0; i <yy.length ; i++) {
                   yy[i]++;
               }
               try {
                   Thread.sleep(40);
               }catch (InterruptedException e){
                   e.printStackTrace();
               }
           repaint();
               for (int i = 0; i <yy.length; i++) {
                   if(yy[i]==800){
                    yy[i]=0;
                   }

               }
           }


    }
}
